package com.qu.waibao.my.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.qu.waibao.R;
import com.qu.waibao.base.BaseRecyclerAdapter;
import com.qu.waibao.bean.Coupon;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @描述 describe
 * @作者 Administrator
 * @创建时间 2018/7/25 17:59
 * @邮箱 1123599561@qq.com
 */
public class CouponAdapter extends BaseRecyclerAdapter<Coupon> {
    public CouponAdapter(Context context, int mode) {
        super(context, mode);
    }

    @Override
    protected RecyclerView.ViewHolder onCreateDefaultViewHolder(ViewGroup parent, int type) {
        return new CouponViewHolder(mInflater.inflate(R.layout.coupon_recycler_item,parent,false));
    }

    @Override
    protected void onBindDefaultViewHolder(RecyclerView.ViewHolder holder, Coupon item, int position) {
        CouponViewHolder couponViewHolder = (CouponViewHolder) holder;
        String state = item.getState();
        couponViewHolder.tv_money.setText(item.getMoneysubtract());
        if(state.equals("1")){ //未使用
            couponViewHolder.rl_root.setBackgroundResource(R.drawable.youhuiquan);
            couponViewHolder.iv_flag.setVisibility(View.GONE);
        }else if(state.equals("3")){ //已使用
            couponViewHolder.rl_root.setBackgroundResource(R.drawable.youhuiquan_h);
            couponViewHolder.iv_flag.setVisibility(View.VISIBLE);
            couponViewHolder.iv_flag.setImageResource(R.drawable.yhq_zhang2);
        }else if(state.equals("2")){ //已过期
            couponViewHolder.rl_root.setBackgroundResource(R.drawable.youhuiquan_h);
            couponViewHolder.iv_flag.setVisibility(View.VISIBLE);
            couponViewHolder.iv_flag.setImageResource(R.drawable.yhq_zhang1);
        }
        couponViewHolder.tv_name.setText(item.getName());
        couponViewHolder.tv_number.setText("编号："+item.getMyquancode());
        couponViewHolder.tv_time.setText("有效时间："+item.getDate_start()+"--"+item.getDate_end());
    }

    class CouponViewHolder extends RecyclerView.ViewHolder{
        @BindView(R.id.tv_name)
        TextView tv_name;
        @BindView(R.id.tv_number)
        TextView tv_number;
        @BindView(R.id.tv_time)
        TextView tv_time;
        @BindView(R.id.tv_money)
        TextView tv_money;
        @BindView(R.id.iv_flag)
        ImageView iv_flag;
        @BindView(R.id.rl_root)
        RelativeLayout rl_root;
        public CouponViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
